/*
 * q_test.c
 *
 *  Created on: 2016-10-30
 *      Author: m
 */

#include "q.h"
#include "string.h"
#include "debug.h"

#define Q_TEST_BUF_LEN  4

void q_test_entry() {
    char q_test_buf[Q_TEST_BUF_LEN];
    u8 c;
    Q q;
    int qr = 0;

    printf("q test start\n");
    q_init(&q, q_test_buf, Q_TEST_BUF_LEN, 1);

    //case 1
    c = 0x12;
    qr = q_push(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 1);

    qr = q_pop(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 0);
    assert(c == 0x12);

    //case 2
    c = 0x12;
    qr = q_push(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 1);

    c = 0x34;
    qr = q_push(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 2);


    qr = q_pop(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 1);
    assert(c == 0x12);

    //case 3
    c = 0x56;
    qr = q_push(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 2);

    c = 0x78;
    qr = q_push(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 3);

    c = 0x90;
    qr = q_push(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 4);

    c = 0xAB;
    qr = q_push(&q, &c);
    assert(qr != 0);
    assert(q_size(&q) == 4);

    //case 4
    qr = q_pop(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 3);
    assert_eq_i(c, 0x34);

    qr = q_pop(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 2);
    assert_eq_i(c, 0x56);

    qr = q_pop(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 1);
    assert_eq_i(c, 0x78);

    qr = q_pop(&q, &c);
    assert(qr == 0);
    assert(q_size(&q) == 0);
    assert_eq_i(c, 0x90);

    qr = q_pop(&q, &c);
    assert(qr != 0);
    assert_eq_i(q_size(&q), 0);
    printf("q test end\n");
}



